import type { ComponentType } from "@/materials/index.d";
import {defineStore} from "pinia";
import type {EditorStore} from './index.d';

const useEditorStore = defineStore('editor', {
    state: (): EditorStore => {
        return {
            componentList: [],
            currentComponentId: ""
        };
    },
    getters: {
        currentComponent(state) {
            return state.componentList.find(
                (comp) => comp.id === state.currentComponentId
            );
        }
    },
    actions: {
        addComponent(component: ComponentType) {
            this.componentList.push(component);
        },
        setCurrentComponentId(id: string) {
            this.currentComponentId = id;
        }
    }
});

export default useEditorStore;